Skip to content

Suppress -Wundef warnings#157

Merged
kou merged 2 commits into
ruby:masterfrom
nobu:gcc-warnings
Oct 22, 2024
Merged

Suppress -Wundef warnings#157
kou merged 2 commits into
ruby:masterfrom
nobu:gcc-warnings

Conversation

@nobu

@nobu nobu commented Oct 22, 2024

Copy link
Copy Markdown
Member

The GCC warning puts undefined macro names in double quotes while clang puts them in single quotes.

The GCC warning puts undefined macro names in double quotes while
clang puts them in single quotes.
@nobu nobu changed the title Supporess -Wundef warnings Suppress -Wundef warnings Oct 22, 2024
Anyway fiddle doesn't need Go closures, just define to 0.
@kou
kou merged commit 7dcb40b into ruby:master Oct 22, 2024
hsbt pushed a commit to hsbt/ruby that referenced this pull request Oct 25, 2024
(ruby/fiddle#157)

The GCC warning puts undefined macro names in double quotes while clang
puts them in single quotes.

ruby/fiddle@7dcb40bccb
hsbt pushed a commit to hsbt/ruby that referenced this pull request Oct 25, 2024
(ruby/fiddle#157)

The GCC warning puts undefined macro names in double quotes while clang
puts them in single quotes.

ruby/fiddle@7dcb40bccb
hsbt pushed a commit to hsbt/ruby that referenced this pull request Oct 26, 2024
(ruby/fiddle#157)

The GCC warning puts undefined macro names in double quotes while clang
puts them in single quotes.

ruby/fiddle@7dcb40bccb
hsbt pushed a commit to ruby/ruby that referenced this pull request Oct 26, 2024
(ruby/fiddle#157)

The GCC warning puts undefined macro names in double quotes while clang
puts them in single quotes.

ruby/fiddle@7dcb40bccb
kou pushed a commit that referenced this pull request Jul 17, 2026
Building fiddle with MSVC against libffi whose `ffitarget.h` defines
`FFI_GO_CLOSURES` unconditionally, for example vcpkg libffi 3.5.2 in a
ruby/ruby mswin build, reports `warning C4005: 'FFI_GO_CLOSURES': macro
redefinition` in every compilation unit. The pre-definition in
`fiddle.h` added by #157 collides with libffi's own definition. GCC and
clang hide the same redefinition because it happens in a system header
there.

The pre-definition only exists to silence `-Wundef` warnings from old
`ffi.h` that tests `#if FFI_GO_CLOSURES` without the target defining it,
and libffi switched that test to `#ifdef` in 3.4.5 (libffi/libffi#796).
This restores the conditional approach of #134, but detects whether the
libffi headers define the macro with `macro_defined?` at `extconf.rb`
time instead of matching compiler-specific warning text, and defines
`FFI_GO_CLOSURES=0` only when they do not. Fiddle itself does not use Go
closures, so the macro only affects which declarations `ffi.h` exposes.

I verified on Windows with MSVC that the eight C4005 warnings disappear
with vcpkg libffi 3.5.2, and that a simulated old libffi header set with
no `FFI_GO_CLOSURES` definition and an `#if FFI_GO_CLOSURES` test still
gets `-DFFI_GO_CLOSURES=0` from `extconf.rb`. `rake test` passes on
`x64-mswin64_140`.

Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants